home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / lang / amigatalk.lha / intuition / Painter.st < prev    next >
Text File  |  2003-11-28  |  9KB  |  336 lines

  1. " ---------------------------------------------------- "
  2. " Painter Class implements simple graphics primitives  "
  3. " ---------------------------------------------------- "
  4.  
  5. Class Painter :Glyph 
  6. ! ownerWindow private fPen bPen oPen drawMode linePattern x y !
  7. [
  8.    setAPen: pen
  9.  
  10.       <primitive 200 0 ownerWindow pen>.
  11.       
  12.       fPen <- pen
  13. |
  14.    setBPen: pen
  15.  
  16.       <primitive 200 1 ownerWindow pen>.
  17.       
  18.       bPen <- pen
  19. |
  20.    setOPen: pen
  21.  
  22.       <primitive 200 2 ownerWindow pen>.
  23.       
  24.       oPen <- pen
  25. |
  26.    setDrawMode: mode
  27.  
  28.       <primitive 200 3 ownerWindow mode>.
  29.       
  30.       drawMode <- mode
  31. |
  32.    setLinePattern: newPatternMask
  33.  
  34.       <primitive 200 21 ownerWindow newPatternMask>.
  35.       
  36.       linePattern <- newPatternMask
  37. |
  38.    getPens
  39.  
  40.       ^ fPen @ bPen
  41. |
  42.    getOPen
  43.  
  44.       ^ oPen
  45. |
  46.    getDrawMode
  47.  
  48.       ^ drawMode
  49. |
  50.    location
  51.  
  52.       ^ x @ y
  53. |
  54.    ownerIs
  55.  
  56.       ^ ownerWindow
  57. |
  58.    movePenTo: newPoint
  59.  
  60.       <primitive 200 4 ownerWindow (newPoint x) (newPoint y)>.
  61.       
  62.       x <- newPoint x.
  63.       y <- newPoint y
  64. |
  65.    drawTo: aPoint
  66.  
  67.       <primitive 200 5 ownerWindow (aPoint x) (aPoint y)>.
  68.       
  69.       x <- aPoint x.
  70.       y <- aPoint y
  71. |
  72.    drawLineFrom: fPoint to: tPoint ! xt yt !
  73.  
  74.       xt <- tPoint x.
  75.       yt <- tPoint y.
  76.       
  77.       <primitive 200 6 ownerWindow (fPoint x) (fPoint y) xt yt>
  78. |
  79.    drawBoxFrom: fPoint to: tPoint
  80.  
  81.       <primitive 200 7 ownerWindow (fPoint x) (fPoint y) (tPoint x) (tPoint y)>
  82. |
  83.    drawCircle: cPoint radius: r
  84.  
  85.       <primitive 200 8 ownerWindow (cPoint x) (cPoint y) r>
  86. |
  87.    drawEllipse: cPoint minaxis: a maxaxis: b
  88.  
  89.       <primitive 200 9 ownerWindow (cPoint x) (cPoint y) a b>
  90. |
  91.    drawPolygon: borderObj         " borderObjects are NOT necessarily Polygons! "
  92.  
  93.       <primitive 200 10 ownerWindow borderObj>
  94.  
  95.       "or <primitive 187 6 ownerWindow borderObj>"
  96. |
  97.    drawPixelAt: aPoint
  98.  
  99.       <primitive 200 11 ownerWindow (aPoint x) (aPoint y)>.
  100.       
  101.       x <- aPoint x.
  102.       y <- aPoint y
  103. |
  104.    drawText: text at: aPoint        " Sorry, no font control for this "
  105.  
  106.       <primitive 200 19 ownerWindow text (aPoint x ) (aPoint y)>
  107. |
  108.    initializeArea: numPoints tmpXSize: xSize tmpYSize: ySize
  109.  
  110.       " You MUST use this method BEFORE using any of the Area/Filled methods
  111.       * down to disposeArea:y: (which MUST be used after you're done
  112.       * with the Area/Filled method(s).  x & y should specify the dimensions
  113.       * of the largest rectangular area that will be drawn:
  114.       "
  115.       ^ private <- <primitive 200 33 ownerWindow numPoints xSize ySize>
  116. |
  117.    drawFilledEllipse: cPoint minaxis: a maxaxis: b
  118.  
  119.       ^ <primitive 200 25 ownerWindow (cPoint x) (cPoint y) a b>
  120. |
  121.    drawFilledCircle: cPoint radius: r
  122.  
  123.       ^ <primitive 200 26 ownerWindow (cPoint x) (cPoint y) r>
  124. |
  125.    areaMoveTo: newPoint
  126.  
  127.       " same as movePenTo: method, only for Area/Filled methods "
  128.       <primitive 200 27 ownerWindow (newPoint x) (newPoint y)>.
  129.       
  130.       x <- newPoint x.
  131.       y <- newPoint y
  132. |
  133.    areaDrawTo: aPoint
  134.  
  135.       " same as drawTo: method, only for Area/Filled methods "
  136.       <primitive 200 28 ownerWindow (aPoint x) (aPoint y)>.
  137.       
  138.       x <- aPoint x.
  139.       y <- aPoint y
  140. |
  141.    drawFilledBoxFrom: fPoint to: tPoint
  142.  
  143.       " This uses the RectFill() function: "
  144.       <primitive 200 29 ownerWindow (fPoint x) (fPoint y) (tPoint x) (tPoint y)>
  145. |
  146.    floodFill: mode at: aPoint
  147.  
  148.       " If mode is 0 (outline mode), every pixel surrounding aPoint that is
  149.       * NOT the outline Pen color will be changed to the flood Pen color (or
  150.       * flood pattern).  If the mode is 1 (color mode), whatever the color is
  151.       * at aPoint and all surrounding pixels of the same color will be flood-
  152.       * filled.  Returns true or false:
  153.       "
  154.       ^ <primitive 200 30 ownerWindow mode (aPoint x) (aPoint y)>.
  155. |   
  156.    areaEnd
  157.  
  158.       " Complete the Area/Filled polygons.  Use this after
  159.       * areaDrawTo:, drawFilledEllipse:minaxis:maxaxis:, 
  160.       * & drawFilledCircle:radius: only
  161.       "
  162.       ^ <primitive 200 31 ownerWindow>
  163. |
  164.    setAreaPattern: patternWords size: size
  165.  
  166.       " patternWords is a ByteArray that is divisible by two.  Each pair of
  167.       * bytes in patternWords is interpreted as a UWORD value.
  168.       * size is a power of two, indicating how tall the pattern is, 
  169.       * which means that the number of elements in patternWords must 
  170.       * be 2 * 2 ^ size.
  171.       * (example: 0 = two ByteArray elements (1 line), 
  172.       * 1 = four elements (2 lines), 
  173.       * 2 = 4 lines, 3 = 8 lines, 4 = 16, etc).  No checking is done, 
  174.       * so get it right (or write your own method!).
  175.       "
  176.       <primitive 200 32 ownerWindow patternWords size>        
  177. |
  178.    outlineOff
  179.  
  180.       " Part of the Area/Filled methods (turn off outlining areas). "
  181.       <primitive 200 35 ownerWindow>
  182. |
  183.    outlineOn
  184.  
  185.       " Part of the Area/Filled methods (turn on outlining areas). "
  186.       <primitive 200 36 ownerWindow>
  187. |
  188.    disposeArea: xSize y: ySize
  189.  
  190.       " xSize & ySize MUST be the same dimensions that were used in the
  191.       * initializeArea:tmpXSize:tmpYSize: method:
  192.       "
  193.       <primitive 200 34 ownerWindow private xSize ySize> 
  194. |
  195.    new: newOwnerWindow
  196.  
  197.       ownerWindow <- newOwnerWindow.
  198.       
  199.       ^ self
  200. ]
  201.  
  202. "----------------------------------------------------"
  203. " Image Class implements Image graphics primitives   "
  204. "----------------------------------------------------"
  205.  
  206. Class Image :Glyph ! private ownerWindow !
  207. [
  208.    ownerIs
  209.  
  210.       ^ ownerWindow
  211. |
  212.    getStartPoint ! left top !
  213.  
  214.       left <- <primitive 200 14 ownerWindow 0 private>.
  215.       top  <- <primitive 200 14 ownerWindow 1 private>.
  216.       
  217.       ^ left @ top
  218. |
  219.    getImageSize ! width height !
  220.  
  221.       width  <- <primitive 200 14 ownerWindow 2 private>.
  222.       height <- <primitive 200 14 ownerWindow 3 private>.
  223.       
  224.       ^ width @ height
  225. |
  226.    setOrigin: aPoint ! x y !
  227.  
  228.       x <- aPoint x.
  229.       y <- aPoint y.
  230.       
  231.       <primitive 200 15 ownerWindow 0 x private>.
  232.       <primitive 200 15 ownerWindow 1 y private>
  233. |
  234.    setExtent: sizePoint ! w h !
  235.  
  236.       w <- sizePoint x.
  237.       h <- sizePoint y.
  238.       
  239.       <primitive 200 15 ownerWindow 2 w private>.
  240.       <primitive 200 15 ownerWindow 3 h private>
  241. |
  242.    setImageDepth: d
  243.  
  244.       <primitive 200 15 ownerWindow 4 d private>
  245. |
  246.    drawImageAt: aPoint
  247.  
  248.       <primitive 200 16 ownerWindow (aPoint x) (aPoint y) private>
  249. |
  250.    drawImageAt: aPoint inState: state
  251.  
  252.       " Valid values for state are:
  253.       *
  254.       *   0 = IDS_NORMAL:           // like drawImageAt:
  255.       *   1 = IDS_SELECTED:         // represents the 'selected state' of a Gadget
  256.       *   2 = IDS_DISABLED:         // the 'ghosted state' of a gadget
  257.       *   3 = IDS_BUSY:             // for future functionality
  258.       *   4 = IDS_INDETERMINATE:    // for future functionality
  259.       *   5 = IDS_INACTIVENORMAL:   // for gadgets in window border
  260.       *   6 = IDS_INACTIVESELECTED: // for gadgets in window border
  261.       *   7 = IDS_INACTIVEDISABLED: // for gadgets in window border
  262.       *   8 = IDS_SELECTEDDISABLED: // disabled and selected
  263.       "
  264.       <primitive 200 22 ownerWindow private state (aPoint x) (aPoint y)>
  265. |
  266.    setImageDataFrom: imageFile
  267.  
  268.       <primitive 200 17 ownerWindow imageFile private>
  269. |
  270.    saveImageIn: imageFile
  271.  
  272.       " true indicates that the Image was saved: "
  273.       ^ <primitive 200 18 ownerWindow imageFile private>
  274. |
  275.    getImageDepth
  276.  
  277.       ^ <primitive 200 14 ownerWindow 4 private>
  278. |
  279.    getImagePlanePick
  280.  
  281.       ^ <primitive 200 14 ownerWindow 6 private>
  282. |
  283.    getImagePlaneOnOff
  284.  
  285.       ^ <primitive 200 14 ownerWindow 7 private>
  286. |
  287.    getNextImage
  288.  
  289.       ^ <primitive 200 14 ownerWindow 8 private>
  290. |
  291.    setImagePlanePick: pp
  292.  
  293.       <primitive 200 15 ownerWindow 6 pp private>
  294. |
  295.    setImagePlaneOnOff: po
  296.  
  297.       <primitive 200 15 ownerWindow 7 po private>
  298. |
  299.    setNextImage: newNextImage
  300.  
  301.       <primitive 200 15 ownerWindow 8 newNextImage private>
  302. |
  303.    grabImageFrom: windowObj startPoint: s endPoint: e ! x1 y1 x2 y2 !
  304.  
  305.       x1 <- s x.
  306.       y1 <- s y.
  307.       x2 <- e x.
  308.       y2 <- e y.
  309.       
  310.       ^ <primitive 200 20 windowObj x1 y1 x2 y2 private>      
  311. |
  312.    pointInImage: testPoint
  313.  
  314.       ^ <primitive 200 23 private (testPoint x) (testPoint y)>
  315. |
  316.    registerTo: newWindowObject
  317.  
  318.       ownerWindow <- newWindowObject
  319. |
  320.    addImage: width height: h depth: d
  321.  
  322.       private <- <primitive 200 13 ownerWindow width h d>.
  323.  
  324.       ^ self
  325. |
  326.    eraseImageStartingAt: aPoint
  327.  
  328.       <primitive 200 24 ownerWindow private (aPoint x) (aPoint y)>
  329. |
  330.    disposeImage
  331.  
  332.       <primitive 200 12 private>.
  333.       
  334.       ^ nil
  335. ]
  336.